//
//  MessageTopView.m
//  TQY
//
//  Created by 甘世清 on 2024/11/10.
//

#import "MessageTopView.h"
#import "IMMessageViewController.h"
@implementation MessageTopView
- (void)SQ_UIViewForSelfView{
    self.backgroundColor = SQHexColor(@"#FFFFFF", 0.98);
    self.layer.cornerRadius = 24;
    self.layer.masksToBounds = YES;
    [self addSubview:self.leftImage];
    [self addSubview:self.rightLabel];
    [self.leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(38);
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(20);
    }];
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self).offset(-10);
        make.left.equalTo(self).offset(70);
        make.right.equalTo(self.mas_right).offset(-10);
    }];
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self).offset(10);
        make.left.equalTo(self).offset(70);
        make.right.equalTo(self.mas_right).offset(-10);
    }];
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = UIColor.clearColor;
    [btn addTarget:self action:@selector(SQ_ButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
    }];
}
-(void)SQ_ButtonClick{
    if (![self.model.messageId isNotEmpty]) {
        return; //如果没房间号
    }
    UIViewController * vc = [Manager SQ_getCurrentViewController];
    if ([vc isKindOfClass:[IMMessageViewController class]]) {
        return;//如果当前在聊天页面
    }
    IMListModel * mo = [TQYFMDBManager SQ_roomIDGetIMListModel:self.model.messageId];
    IMMessageViewController * view = [[IMMessageViewController alloc]init];
    view.listModel = mo;
    [vc.navigationController pushViewController:view animated:YES];
}

- (void)setModel:(IMMessageModel *)model{
    _model = model;
    [self.leftImage sd_setImageWithURL:SQURLImage(model.toUserPortrait) placeholderImage:SQGetImage(@"zanwutouxiang")];
    self.rightLabel.text = model.content;
    self.nameLabel.text = model.toUserName;
}
- (UIImageView *)leftImage{
    if (!_leftImage) {
        _leftImage = [[UIImageView alloc]init];
        _leftImage.contentMode = UIViewContentModeScaleAspectFill;
        _leftImage.clipsToBounds = YES;
        _leftImage.layer.cornerRadius = 19;
        _leftImage.layer.masksToBounds = YES;
    }
    return _leftImage;
}
- (UILabel *)rightLabel{
    if (!_rightLabel) {
        _rightLabel = [[UILabel alloc]init];
        _rightLabel.font = FONT_REGULAR(14);
        _rightLabel.textColor = SQColor333333;
    }
    return _rightLabel;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(16);
        _nameLabel.textColor = SQColor333333;
    }
    return _nameLabel;
}

@end
